<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>主题列表</title>
	<%@ include file="/common/meta.jsp"%>
	<%@ include file="/common/common.jsp"%>
	<script type="text/javascript" src="${ctx}/js/jquery.uniform.js"></script>
</head>
<body>
<s:set name="siteId" value="#session['CURRENT_SITE'].siteId"></s:set>
<div id="wrapper">
	<div class="curmb"><s:text name="your.site.position"/>:<a href="${ctx}/main.action"><s:text name="homepage"/></a><span>></span><s:text name="theme.title"/></div>
	<div class="listtit" id="listtit"><p><span><strong><s:text name="theme.list"/></strong></span></p></div>
	<div class="searchbox">
   		<form id='uploadForm' name="uploadForm" enctype="multipart/form-data"  method="post">
			<table class="searchTable">
				<tr>
					<td><input type="file" name="uploadFile" id="uploadFile" class="txtsearch" /> 
					


					
					</td>
					<td>
					       <s:if test="%{authLicence('1_1_6')}"><input type="button" value="上传" class="btnsearch" id="upload_btn"/></s:if>
					       <s:else><input type="button" value="上传" class="btnsearch" disabled="disabled" id="upload_btn"/></s:else>



					</td>
				</tr> 
			</table>
	   	</form>
		<div class="clear"></div>
	</div>
	<div class="listboxb" id="listbox">
		<div class="themewrapper" id = "theme_list_div">			 
			<s:iterator value="themeBeans" status="var">
				<div class="themebox">
					<div class="themepic"  >						
						<s:if test="themeStatus">
							<img id="src_${var.index}" src="<s:property value="imagepath" />" width="157" height="117" title="缩略图" />
						    <s:if test="%{authLicence('1_1_6')}">
						    	<input type="button" class="btnlist2" value="禁用" name="bottom_theme_oper_btn" id="btn_${var.index}"/>
						    </s:if>
						    <s:else><input type="button" disabled="disabled" class="btnlist2" value="禁用" name="bottom_theme_oper_btn" id="btn_${var.index}"/></s:else>
						</s:if>
						<s:else>
							<img id="src_${var.index}" src="<s:property value="imagepath" />" width="157" height="117" title="缩略图" class="themepic_shadow"/>
							 <s:if test="%{authLicence('1_1_6')}">
							  <input type="button" class="btnlist2" value="启用" name="bottom_theme_oper_btn" id="btn_${var.index}"/>
							</s:if>
							 <s:else><input type="button" disabled="disabled" class="btnlist2" value="启用" name="bottom_theme_oper_btn" id="btn_${var.index}"/></s:else>
						</s:else>	
						<input type="hidden" name="key" id="hidden_${var.index}"  value="<s:property value="themeId"/>"/>				 					
						<tt class="themetit"><span><s:property value="themeName"/></span></tt>
					</div>
				</div>			 
			</s:iterator>
			<div class="clear"></div>
	    </div>	 
	</div>

</div>


    <script type="text/javascript" charset="utf-8">
      $(function(){
        $("input, textarea, select, button").uniform();
      });
    </script>


</body>
</html>
<script src="${ctx}/js/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript" defer="defer">
	$(function(){ 		 
	    $("#upload_btn").click(function(){	    	
	    	uploadFormSubmit();
	    });
	    var i=0;
	   
	    $("#theme_list_div").find("input[name='bottom_theme_oper_btn']").each(function(i,it){		 
	    		 $(it).click(function(){
	    			 var id = $(it).attr("id");
	    			 if(id){
	    				 var arr = id.split('_');
	    				 var index = arr[1];	    				 
	    				 themeStatusSubmit($('#hidden_'+index).val(),index);
	    			 }
	    		 });
	    	});
	 });	
 
	function getAllIds(){
		var arr = new Array();
		$("input[name='key']:checked").each(function(i,item){
			arr.push($(item).val());
		});
		return arr.join('-');
	}
	
	function themeStatusSubmit(id,index){
		if(id){
			$.ajax({
				url:"${ctx}/theme/theme-change.action?t="+new Date().getTime(),
				data:{'objectId':id},
				type:"get",
				dataType:"text",
				success:function(data){
					var json = eval('('+data+')');
					if(json.flag){
						 if(json.show){ // 当前状态变成禁用，图片css变灰，按钮显‘示启用’
							 /* 	 $("#src_"+index).css()   处理CSS 禁用css */
							 $("#btn_"+index).parent("div").children("img").addClass("themepic_shadow");
							 $("#btn_"+index).val("启用");
						 }else{ // 当前状态变成禁用，图片css变灰，按钮显‘示启用’
							 $("#btn_"+index).parent("div").children("img").removeClass("themepic_shadow");
							 $("#btn_"+index).val("禁用"); 
						 }
					}else{
						alert(json.msg);
					}			
				}
			});
		}else{
			alert('请选择要操作的对象');
		}
	}
	
	function reshowImg(ids,flag){
		var arr = new Array();
		var arr = ids.split('-');
		$("input[name='key']").each(function(j,item){
			for(var i=0;i<arr.length;i++){
				var id = $(item).val();
				if(id==arr[i]){
					//$("#img_"+id)  对该对象进行操作 把缩略图图片变灰
					if(flag){						
						alert("id为：'img_"+id+"'的图片点亮");
					}else{
						alert("id为：'img_"+id+"'的图片变成灰色");
					}
				}
			}
		});
	}
	
	function uploadFormSubmit(){
		var path = $("#uploadFile").val();
		if(path){
			ajaxSubmitForm();
		}else{
			alert("请选择文件，再上传");
		}
	}
	function ajaxSubmitForm(){
		$("#uploadForm").ajaxSubmit({
			url:"${ctx}/theme/theme-upload.action",
			dataType:"text",
			type:"post",
			success:function(data){
				var json =eval('('+$(data).text()+')');
				if(json.flag){
					alert(json.msg);
					window.location='${ctx}/theme/theme-list.action';
				}else{
					alert(json.msg);
				}
			}
		});
	}
	
	
	</script>